using UnityEngine;
using QFramework;
using Cysharp.Threading.Tasks;
using Unity.VisualScripting;

public class UIManager : AbstractSystem
{
    public Transform UIRoot;
    public GameObject CurrentPanel;
    protected override void OnInit()
    {
        
    }

    public async UniTask OpenUIPanel(string path)
    {
        Debug.Log("MainArchitecture.LoadGameStart");
        if(CurrentPanel!=null)
        {
            GameObject.Destroy(CurrentPanel);
            await UniTask.Yield();
        }
        // var handle = await Resources.LoadAsync("UIPanel/UIStartGame/UIStartGame");
        var handle = await Resources.LoadAsync(path);
        var go = handle.GameObject();
        CurrentPanel = GameObject.Instantiate(go, UIRoot);
    }

    public void ClosePanel()
    {
        if(CurrentPanel!=null)
        {
            GameObject.Destroy(CurrentPanel);
        }
    }
}